package com.wanghao.ui;

import java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.wanghao.OutputItem;
import com.wanghao.proxy.OutputManAdapter;

public class OutputFrame extends Composite {

	public class OutputUIItem extends Composite {

		public OutputUIItem(Composite parent, int style, String aTitle,
				String aContent) {
			super(parent, style);

			Create(aTitle, aContent);
		}

		private void Create(String aTitle, String aContent) {
			Label label = new Label(this, SWT.NONE);
			label.setText(aTitle);

			Text content = new Text(this, SWT.MULTI);
			content.setText(aContent);

			setLayout(new RowLayout(SWT.HORIZONTAL));
		}
	};

	private OutputManAdapter outputManAdapter;
	private ArrayList<OutputUIItem> itemList;

	public OutputFrame(Composite parent, int style) {
		super(parent, style);
		itemList = new ArrayList<OutputUIItem>();
	}

	public void Refresh(OutputManAdapter aAdapter) {
		outputManAdapter = aAdapter;

		itemList.clear();
		for (OutputItem item : outputManAdapter.ItemList()) {
			OutputUIItem uiItem = new OutputUIItem(this, SWT.BORDER, item
					.getTitle(), item.getContent());
			itemList.add(uiItem);
		}

		setLayout(new RowLayout(SWT.VERTICAL));
	}
}
